﻿
namespace SuperGo.SilverlightLib {
	public class GameState {
        public static readonly GameState BlackToMove = new GameState(1, "BlackToMove", Player.Black);
		public static readonly GameState WhiteToMove = new GameState(2, "WhiteToMove", Player.White);
		public static readonly GameState NegotiatingDeadStones = new GameState(3, "NegotiatingDeadStones", null);
		public static readonly GameState BlackResigned = new GameState(4, "BlackResigned", null);
		public static readonly GameState WhiteResigned = new GameState(5, "WhiteResigned", null);
		public static readonly GameState DeadStonesMergedGameOver = new GameState(6, "DeadStonesMergedGameOver", null);

		private readonly int _id;
        private readonly string _name;
        private readonly Player _player;

		private GameState(int id, string name, Player player) {
            _id = id;
            _name = name;
            _player = player;
        }

        public int Id {
            get { return _id; }
        }

        public string Name {
            get { return _name; }
        }

		public override bool Equals(object obj) {
            if (obj is GameState) {
                return ((GameState)obj).Id == Id;
            }
            return base.Equals(obj);
        }

        public override int GetHashCode() {
            return Id;
        }

        public Player ToPlayer() {
            if (_player != null) {
                return _player;
            }
            return null;
        }
    }
}
